package com.doit.day07

import org.apache.commons.lang3.RandomUtils

object _05_闭包 {
  def main(args: Array[String]): Unit = {
    val fx = (a:Int,b:Int)=>{
      a+b
    }

    val fxx: Int => Int => Int = (a:Int) => {
      (b:Int)=>a+b
    }

    val res = fxx(3)(10)


    val f = () => {
      var p = RandomUtils.nextInt(1,10)

      val inner = () => {
        p += 1
        p
      }
      inner
    }

    val x1: () => Int = f()
    //这种现象就就叫传说中的闭包
    //创建了一个随机数是个2
    println(x1())//3
    //此时的p就是等于3 +1 =4
    println(x1())//4
    println(x1())//5
    println(x1())//6
    println(x1())//7
    println(x1())//8
//
    println("-----------")
//
    println(f()())
    println(f()())
    println(f()())
  }

}
